package com.accp.restaurant.controller;


import com.accp.restaurant.entity.Orders;
import com.accp.restaurant.service.OrderService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Controller
@RequestMapping("/Order")
public class OrderController {

    @Autowired
    private OrderService orderService;



    @RequestMapping("/query")
    @ResponseBody
    public Map<String,Object> query(@RequestParam(value = "pageNumber",defaultValue = "1",required = false)Integer pageNumber, @RequestParam(value = "pageSize",defaultValue = "5",required = false) Integer pageSize, Orders orders){
        Map<String,Object> map = new HashMap<String,Object>();
        map.put("rows",orderService.query(pageNumber,pageSize,orders.getOrderid(),orders.getOrdertime()));
        map.put("total",orderService.getCount(pageNumber,pageSize,orders.getOrderid(),orders.getOrdertime()));
        return map;
    }

    @RequestMapping("/findById")
    @ResponseBody
    public List<Orders> findById(@RequestParam(value = "pageNumber",defaultValue = "1",required = false)Integer pageNumber, @RequestParam(value = "pageSize",defaultValue = "5",required = false) Integer pageSize, String orderid){
        System.out.println(orderid+"--------------------------------------------------");
        return orderService.findById(pageNumber,pageSize,orderid);
    }





}
